package com.ywq.app.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ArtClass implements Serializable {

	private static final long serialVersionUID = -4316180995919582463L;
	
	public ArtClass(){ }
	private String identifier;
	private String name;
	private String parent;
	private Integer deep;
	private Boolean enabled;
	public Boolean getEnabled() {
		return enabled;
	}
	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}
	private Date gmtCreated;
	private Date gmtModified;
	private String type;
	private List<ArtClass> children = new ArrayList<ArtClass>();
	private String parentName;
	public String getParentName() {
		return parentName;
	}
	public void setParentName(String parentName) {
		this.parentName = parentName;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public List<ArtClass> getChildren() {
		return children;
	}
	public void setChildren(List<ArtClass> children) {
		this.children = children;
	}

	public static String treeJson = "";

	public String getIdentifier() {
		return identifier;
	}

	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getParent() {
		return parent;
	}

	public void setParent(String parent) {
		this.parent = parent;
	}

	public Integer getDeep() {
		return deep;
	}

	public void setDeep(Integer deep) {
		this.deep = deep;
	}
	public Date getGmtCreated() {
		return gmtCreated;
	}

	public void setGmtCreated(Date gmtCreated) {
		this.gmtCreated = gmtCreated;
	}

	public Date getGmtModified() {
		return gmtModified;
	}

	public void setGmtModified(Date gmtModified) {
		this.gmtModified = gmtModified;
	}

	// 构建树
	public static String buildClassTree(List<ArtClass> classList) {
		ArtClass c = new ArtClass();
		for (int i = 0; i < classList.size(); i++) {
			c = classList.get(i);
			treeJson += "{\"text\": \"" + c.getName() + "\",\"id\":\"" + c.getIdentifier() + "\"";
			if (c.getChildren() == null || c.getChildren().size() == 0) {
				treeJson += ",\"url\":\"\"";
			}
			if (c.getChildren() != null && c.getChildren().size() > 0) {
				treeJson += ",\"isexpand\": false ,\"children\": [";
				buildClassTree(c.getChildren());
				treeJson += "]";
			}
			treeJson += "}";
			if ((i + 1) < classList.size()) {
				treeJson += ",";
			}
		}
		return treeJson;
	}

	public static String getClassTree(List<ArtClass> classList) {
		treeJson = "[";
		String tree = buildClassTree(classList);
		tree += "]";
		return tree;
	}
}
